<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>设置我的资料</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiAdmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiAdmin/style/admin.css" media="all">
    <link href="../../layuiAdmin/lib/extend/wangeditor/style.css" rel="stylesheet">
    <script src="../../layuiAdmin/lib/extend/wangeditor/index.js"></script>
</head>

<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">设置我的资料</div>
                    <div class="layui-card-body" pad15>
                        <div class="layui-form" id="popup-from">
                            <div class="layui-row">
                                <div class="layui-col-xs6">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">用户名</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="cUserName" style="background:#eeeeee" value="" readonly class="layui-input">
                                        </div>
                                        <div class="layui-form-mid layui-word-aux">不可修改。一般用于后台登入名</div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">昵称</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="cName" value="" lay-verify="nickname" autocomplete="off" placeholder="请输入昵称" class="layui-input">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">性别</label>
                                            <div class="layui-input-block">
                                                <input type="radio" name="cGender" value="1" title="男">
                                                <input type="radio" name="cGender" value="2" title="女" checked>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">手机</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="cTel" autocomplete="off" class="layui-input">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">邮箱</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="email" autocomplete="off" class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-xs6">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">头像</label>
                                        <input type="text" name="cAvatar" class="layui-input layui-hide">
                                        <img src="" style="width:200px; display:none;" name="cImgUrl" />
                                        <button type="button" class="layui-btn layui-btn-primary" id="Iconfile">
                                            <i class="layui-icon">&#xe67c;</i>上传图片
                                        </button>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">个人简介</label>
                                <div class="layui-input-block" style="border:2px solid #eeeeee;">
                                    <div id="toolbar-container"></div>
                                    <div id="editor-container" style="height: 450px;border-top: 2px solid #eeeeee;"></div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="form-submit">确认修改</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重新填写</button>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        document.write("<script type='text/javascript' src='../../layuiAdmin/xin.js?v=" + new Date().getTime() + "'><\/script>");
    </script>
    <script src="../../layuiAdmin/layui/layui.js"></script>
    <script>
        layui.config({
            base: '../../layuiAdmin/', //静态资源所在路径
            version: top.layui.setter.version
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'set', 'upload'], function () {
            var $ = layui.$,
                setter = layui.setter,
                admin = layui.admin,
                upload = layui.upload,
                form = layui.form;
            var E = window.wangEditor; // 全局变量

            var session_data = layui.sessionData(setter.tableName);
            var id = session_data.UserInfo.user.cId;
            upload.render({
                elem: '#Iconfile',
                url: "/api/Upload/Upload",
                data: { type: 'userIcon' },
                done: function (res) {
                    if (res.code == 200) {
                        $("img[name='cImgUrl']").attr("src", $.GetPathUri() + res.data);
                        $("img[name='cImgUrl']").show();
                        $("#Iconfile").hide();;
                        $("input[name='cAvatar']").val(res.data);
                    } else {
                        parent.layer.msg('上传失败!\n' + res.info, { icon: 2, time: 2000 });
                    }
                }
            });
            $("img[name='cImgUrl']").on('click', function () {
                $("#Iconfile").click();
            });

            // 编辑器配置
            const editorConfig = { MENU_CONF: {} }
            editorConfig.placeholder = '请输入内容'
            editorConfig.MENU_CONF['uploadImage'] = {
                // 上传图片的配置
                server: $.GetPathUri() + '/api/base/WeditorUpload',
                allowedFileTypes: ['image/*'],
            }
            // 创建编辑器
            const editor = E.createEditor({
                selector: '#editor-container',
                config: editorConfig,
                mode: 'default' // 或 'simple' 参考下文
            })
            // 创建工具栏
            const toolbar = E.createToolbar({
                editor,
                selector: '#toolbar-container',
                config: {},
                mode: 'default' // 或 'simple' 参考下文
            })
            //获取表单值
            if (id != "") {
                admin.req({
                    type: 'get',
                    url: "/api/User/GetUserByUserId?userId=" + id,
                    success: function (r) {
                        if (r.code == 200) {
                            editor.setHtml('<p>hello</p>');
                            if (r.data.cIcon != null && r.data.cIcon != "") {
                                $("img[name='cImgUrl']").attr("src", $.GetPathUri() + r.data.cIcon);
                                $("img[name='cImgUrl']").show();
                                $("#Iconfile").hide();
                            }
                            $("#popup-from").SetFormData(r.data);
                            form.render();
                        }
                    }
                })
            }
            //保存表单
            form.on('submit(form-submit)', function (data) {
                var field = data.field; //获取提交的字段
                alert(editor.getHtml());
                //提交
                // admin.req({
                //   type: 'post',
                //   url: "/api/Staff/EditStaff",
                //   data: field,
                //   success: function (data) {
                //     if(data.code == 200) {
                //       parent.layer.msg('操作成功!', { icon: 1, time: 1000 });
                //     } else {
                //       layer.msg('操作失败!\n' + data.msg, { icon: 2, time: 1000 });
                //     }
                //   }
                // });
            });
        });
    </script>
</body>

</html>